//
//  HomeTableViewCell.m
//  DriverUse
//
//  Created by angra on 16/11/2.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "HomeOrderModel.h"

@interface HomeTableViewCell()
@property (nonatomic,weak)UILabel *startLabel;
@property (nonatomic,weak)UILabel *endLabel;
@property (nonatomic,weak)UILabel *personPriceLabel;
@property (nonatomic,weak)UILabel *dateLabel;
@property (nonatomic,weak)UILabel *timeLabel;
@property (nonatomic,weak)UILabel *typeLabel;
@end

@implementation HomeTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = kColoeString(@"f7f7f7");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setInterface];
    }
    return self;
    
}
-(void)setInterface
{

    UIView *backView = [[UIView alloc]init];
    backView.backgroundColor = kWhiteColor;
    [self.contentView addSubview:backView];
    
    
    UILabel *startLabel = [self createLabelWithText:@"新疆维吾尔自治区" font:15 textColor:@"333333"];
    [backView addSubview:startLabel];
    _startLabel = startLabel;
 
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = kColoeString(@"333333");
    [backView addSubview:lineView];
    
    UILabel *endLabel = [self createLabelWithText:@"宁夏回族自治区" font:15 textColor:@"333333"];
    [backView addSubview:endLabel];
    _endLabel = endLabel;
    
    UILabel *personPriceLabel = [self createLabelWithText:@"4人 ¥200" font:12 textColor:@"ff3333"];
    [backView addSubview:personPriceLabel];
    _personPriceLabel = personPriceLabel;
    
    UILabel *dateLabel = [self createLabelWithText:@"2016年08月03日" font:12 textColor:@"666666"];
    [backView addSubview:dateLabel];
    _dateLabel = dateLabel;
    
//    UILabel *timeLabel = [self createLabelWithText:@"17:50" font:12 textColor:@"666666"];
//    [backView addSubview:timeLabel];
//    _timeLabel = timeLabel;
    
    UIView *lineView1 = [[UIView alloc]init];
    lineView1.backgroundColor = kColoeString(@"e5e5e5");
    [backView addSubview:lineView1];
    
    UILabel *typeLabel = [self createLabelWithText:@"全部已支付" font:12 textColor:@"333333"];
    [backView addSubview:typeLabel];
    _typeLabel = typeLabel;
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(kScaleNum(10));
        make.right.equalTo(self.contentView).offset(kScaleNum(-10));
        
        make.top.equalTo(self.contentView).offset(kScaleNum(5));
        make.bottom.equalTo(self.contentView);
    }];
    
    [startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView).offset(kScaleNum(15));
        make.top.equalTo(backView).offset(kScaleNum(7));
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel.mas_right).offset(kScaleNum(5));
        make.height.equalTo(@(1));
        make.width.equalTo(@(kScaleNum(30)));
        make.centerY.equalTo(startLabel);
    }];
    

    
    [personPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backView).offset(kScaleNum(-5));
        make.top.equalTo(backView).offset(kScaleNum(8));
    }];
    
    [endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lineView.mas_right).offset(kScaleNum(5));
        make.centerY.equalTo(startLabel);
//        make.right.equalTo(personPriceLabel.mas_left).offset(kScaleNum(-5));
    }];
    
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel);
        make.top.equalTo(startLabel.mas_bottom).offset(kScaleNum(6));
    }];
    
//    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(dateLabel.mas_right).offset(15);
//        make.centerY.equalTo(dateLabel);
//    }];
//    
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(backView);
        make.height.equalTo(@(0.5));
        make.top.equalTo(dateLabel.mas_bottom).offset(kScaleNum(6));
    }];
    
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView).offset(kScaleNum(13));
        make.top.equalTo(lineView1.mas_bottom).offset(kScaleNum(4));
    }];

    
    
}
-(UILabel *)createLabelWithText:(NSString *)text font:(CGFloat)font textColor:(NSString *)hexColor
{
    UILabel *label = [[UILabel alloc]init];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font(kScaleNum(font))];
    label.textColor = kColoeString(hexColor);
    return label;
}
-(void)setModel:(HomeOrderModel *)model
{
    _model = model;
    _startLabel.text = model.route_s;
    _endLabel.text = model.route_e;
    _personPriceLabel.text = [NSString stringWithFormat:@"%d人 ¥%@",model.order_num,model.order_amt];
    _typeLabel.text = model.order_status;
    _dateLabel.text = model.date_s;
    
}
@end
